<?php
namespace yan\googlebusiness\model;
class Product{
    const CHANNEL = 'online';
    // The product details are provided in English
    const CONTENT_LANGUAGE = 'en';
    // The products are sold in the United States
    const TARGET_COUNTRY = 'HK';
    
    public $kind;
    public $id;
    public $offerId;
    public $title;
    public $description;
    public $link;
    public $image_link;
    public $availability;
    public $availability_date;
    public $brand;
    public $color;
    public $condition;
    public $gender;
    public $gtin;
    public $mpn;
    public $price;
    public $content_language;
    public $target_country;
    public $channel;
    public function __construct()
    {
        $this->init();
    }
    public function init(){
        $this->availability_date = date('Y-m-d\TH:iP', strtotime("+1 month"));
        $this->gender = 'unisex';
        $this->condition = 'new';
        $this->kind = 'content#product';
        $this->content_language = self::CONTENT_LANGUAGE;
        $this->target_country = self::TARGET_COUNTRY;
        $this->channel = self::CHANNEL;
    }
    public function setPrice($price, $currency = 'HKD'){
        $this->price = join(' ', [$price, $currency]);
    }
    public function setQuanitity($quanity){
        if($quanity >0){
            $this->availability = 'in_stock';
        }else{
            $this->availability = 'out_of_stock';
        }
    }
    public function toString(){
        $arr = $this->toArray();
        return json_encode($arr);
    }
    public function toArray(){
        return get_object_vars($this);
    }
}